From 22096dee1c72f8aa35aae6edaab908bf18e6e504 Mon Sep 17 00:00:00 2001 From: Nathanael Jones Date: Mon, 6 Feb 2017 17:16:33 -0700 Subject: [PATCH] Fix #3658 .cargo/config prevents freshness (sort if sourced from HashMap) --- src/cargo/ops/cargo_compile.rs | 4 ++++ src/cargo/ops/cargo_rustc/custom_build.rs | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index ec13b2a2e..acc2fdf35 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -528,6 +528,10 @@ fn scrape_target_config(config: &Config, triple: &str) output.metadata.push((k.clone(), val.to_string())); } } + + // We randomized the data source with HashMaps, so we must sort the resulting vectors + // to produce a deterministic result + output.sort(); } ret.overrides.insert(lib_name, output); } diff --git a/src/cargo/ops/cargo_rustc/custom_build.rs b/src/cargo/ops/cargo_rustc/custom_build.rs index ea3e0f98c..431559868 100644 --- a/src/cargo/ops/cargo_rustc/custom_build.rs +++ b/src/cargo/ops/cargo_rustc/custom_build.rs @@ -406,6 +406,17 @@ impl BuildOutput { } Ok((library_paths, library_links)) } + + /// Sort the contents of the struct for consistent hashing. + /// Suggested if populated from a HashMap instead of a order-preserving data source + pub fn sort(&mut self){ + self.library_paths.sort(); + self.library_links.sort(); + self.cfgs.sort(); + self.metadata.sort(); + self.rerun_if_changed.sort(); + self.warnings.sort(); + } } /// Compute the `build_scripts` map in the `Context` which tracks what build -- 2.30.2